<?php

/**
 * Description of code_util
 *
 * @copyright (c) 2011 University of Geneva
 * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
 * @author Laurent Opprecht
 */
class CodeUtil
{
    public static function class_rename($old_name, $new_name, $text){
         $result = preg_replace('/class\s+'.$old_name.'\s+/', 'class '.$new_name.' ', $text);
         return $result;
    }
    
    public static function file_append($adder, $text){
        $pattern = "/defined\('INTERNAL'\)\s+\|\|\s+die\(\);/";
        $anchor = "defined('INTERNAL') || die();";      
        $result = preg_replace($pattern, $anchor . "\n" . $adder, $text);
        return $result;
    }
    
    public static function file_remove($adder, $text){        
        $pattern = "#defined\('INTERNAL'\)\s+\|\|\s+die\(\);\s+" . preg_quote($adder) .'#';
        $anchor = "defined('INTERNAL') || die();";        
        $result = preg_replace($pattern, $anchor, $text);
        return $result;
    }
}

?>
